package cn.ecut.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.Charset;


public class BrowserFilter implements Filter {
    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        // 进行整体 的过滤器 的功能
        HttpServletRequest request = (HttpServletRequest)req ;
        HttpServletResponse response = (HttpServletResponse)resp ;

        String userAgent = request.getHeader("user-agent");
//        System.out.println("userAgent：" + userAgent);
        // 判断用户使用的浏览器类型
        if (userAgent.contains("Trident")){
            response.getWriter().write("you are using IE browser!");
            response.sendError( HttpServletResponse.SC_FORBIDDEN , "can not use IE browser!"  );
        }
        // 将 数据 继续执行。
        chain.doFilter( request , response );
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void destroy() {

    }
}
